package org.ocean.online.wicket;

import java.io.File;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
import org.ocean.online.sys.DbGuard;
import org.ocean.online.sys.DbGuardFactory;
import org.ocean.online.utils.OnlineUtil;
import org.ocean.online.utils.UserUtil;
import org.ocean.online.web.Login;

public class NeedLoginPage extends BaseWebPage{
	private static final long serialVersionUID = 1L;

	public NeedLoginPage(){
		if(getUser()==null){
			this.getPage().redirectToInterceptPage(new Login());
		}else{
			System.out.println("user online: "+getUser());
		}
	}
	
	protected Map getUser(){
		return (Map) getHttpSession().getAttribute("user");
	}
	
	protected String getUsername(){
		return (String) getUser().get("username");
	}
	protected DbGuard getDb(){
		
		return DbGuardFactory.getDbGuard(getUsername());
	}
	
	protected HttpSession getHttpSession(){
		HttpServletRequest servletRequest = ((ServletWebRequest) getRequest()).getContainerRequest();
		return servletRequest.getSession();
	}
	
	protected String getParamValue(String key){
		return this.getRequest().getRequestParameters().getParameterValue(key).toString("");
	}
	
	protected String getWorkspace(){
		return OnlineUtil.getWorkspace(getUsername());
	}
}
